package com.example.back_code.controller;

import com.example.back_code.entity.po.HorizontalProject;
import com.example.back_code.service.HorizontalProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/horizontal-project")
public class HorizontalProjectController {

    @Autowired
    private HorizontalProjectService horizontalProjectService;

    @GetMapping("/list")
    public List<HorizontalProject> list() {
        return horizontalProjectService.list();
    }

    @PostMapping("/add")
    public boolean add(@RequestBody HorizontalProject project) {
        return horizontalProjectService.save(project);
    }

    @PutMapping("/update")
    public boolean update(@RequestBody HorizontalProject project) {
        return horizontalProjectService.updateById(project);
    }

    @DeleteMapping("/delete/{id}")
    public boolean delete(@PathVariable Long id) {
        return horizontalProjectService.removeById(id);
    }

    // 审核接口
    @PostMapping("/audit")
    public boolean audit(@RequestParam Long id, @RequestParam Integer status, @RequestParam(required = false) String rejectReason) {
        return horizontalProjectService.auditProject(id, status, rejectReason);
    }

    // 筛选接口
    @GetMapping("/filter")
    public List<HorizontalProject> filter(
            @RequestParam(required = false) String projectName,
            @RequestParam(required = false) String startDate,
            @RequestParam(required = false) String endDate,
            @RequestParam(required = false) Integer status
    ) {
        return horizontalProjectService.filterProjects(projectName, startDate, endDate, status);
    }
} 